#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "iot_gpio.h"
#include "iot_i2c.h"
#include "iot_uart.h"

#include "dtuhardware.h"

#define LED_GPIO 9
#define KEY1_GPIO 5
#define KEY2_GPIO 7
#define DTU_UART 2

void LED_INIT(void){
    IoTGpioInit(LED_GPIO);
    IoTGpioSetDir(LED_GPIO, IOT_GPIO_DIR_OUT);
}

void KEY_INIT(void){
    IoTGpioInit(KEY1_GPIO);
    IoTGpioSetDir(KEY1_GPIO, IOT_GPIO_DIR_IN);
    IoTGpioInit(KEY2_GPIO);
    IoTGpioSetDir(KEY2_GPIO, IOT_GPIO_DIR_IN);
}

void I2C_INIT(void){

}

void UART_INIT(void){
    IoTUartDeinit(DTU_UART);
    IotUartAttribute uartAttr;
    uartAttr.baudRate = 115200;
    uartAttr.dataBits = IOT_UART_DATA_BIT_8;
    uartAttr.stopBits = IOT_UART_STOP_BIT_1;
    uartAttr.parity = IOT_UART_PARITY_NONE;
    IoTUartInit(DTU_UART, &uartAttr);

    osDelay(20);

    IoTUartDeinit(0);
    IotUartAttribute uart485;
    uart485.baudRate = 9600;
    uart485.dataBits = IOT_UART_DATA_BIT_8;
    uart485.stopBits = IOT_UART_STOP_BIT_1;
    uart485.parity = IOT_UART_PARITY_NONE;
    IoTUartInit(0, &uart485);

    osDelay(20);
}